<?php
$token = "50b4175a 67f479ed 93192570 7bf577b9 b9007205 fc5984a5 b1c9758d 41c06947";
$token = "6cfaa206281fa5ffb69f1800a75fc9a060efa730276b2fb8c9c9bdc19bcc1719";

$aps['aps']['alert'] = 'test啦';
$aps['aps']['badge'] = 5;
$aps['aps']['sound'] = 'beep.wav';

//发两条
$payload = json_encode($aps);
echo $payload."\n";

//$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsHost = 'gateway.push.apple.com'; 
$apnsPort = 2195;
$apnsCert = 'cer/wanlitong_prod_ck.pem';
$streamContext = stream_context_create();
var_dump($streamContext);
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
var_dump($streamContext);
stream_context_set_option($streamContext, 'ssl', 'passphrase', "pawlt888888");
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 30, STREAM_CLIENT_CONNECT, $streamContext);
$msg = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $token)) . chr(0) . chr(strlen($payload)) . $payload;
//$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $token)) . pack("n",strlen($payload)) . $payload; 
fwrite($apns, $msg);
fclose($apns);
?>
